package service.mail;

import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

import javax.mail.MessagingException;

public class LocalMailer implements Mailer {
    private MailSender mailSender;

    public void postMail(String[] recipients, String subject, String message, String from) throws MessagingException {
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setTo(recipients);
        mail.setSubject(subject);
        mail.setText(message);
        if (from != null && !from.equals("") && !from.equals(" ")) {
            mail.setFrom(from);
        }
        mailSender.send(mail);
    }

    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }
}